#include "thread_pool.h"

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

static void *add(void *pv) {
	while (pthread_mutex_trylock(&mutex)) {
		usleep(1000);
	}
	++(*(int *)pv);
	pthread_mutex_unlock(&mutex);
	return NULL;
}

int main(void) {
	thread_pool_create(10);
	int n = 10;
	for (int i = 0; i < 1000 * 1000; ++i) {
		thread_pool_run(add, &n);
	}
	sleep(1);
	printf("n = %d\n", n);
	pthread_mutex_destroy(&mutex);
	thread_pool_destory();
	return 0;
}